<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
    <title th:text="'编辑'+${entityData.entityComment}"></title>
    <meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">

	<link rel="stylesheet" href="../layui-v2.5.5/css/layui.css" media="all" />
	<link rel="stylesheet" href="../css/global.css" media="all">
	<link rel="stylesheet" href="../css/table.css" />
	<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
	<div style="margin: 15px;">
		<form class="layui-form" action="">
			<div class="layui-form-item" th:each="entity : ${entityData.entityAttrs}">
				<label class="layui-form-label" th:text="${entity.value}"></label>
				<div class="layui-input-block">
					<input type="text" th:attr="name=${entity.key}" value="" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" style="text-align: center;">
				<div class="layui-input-block" style="margin-left:0px;">
					<button class="layui-btn" lay-submit lay-filter="save">保存</button>
					<button type="button" class="layui-btn layui-btn-primary" id="cancerBtn">取消</button>
				</div>
			</div>
			
		</form>
	</div>
	<script type="text/javascript" src="../layui-v2.5.5/layui.js"></script>
	<script type="text/javascript" src="../js/base.js"></script>
	<script th:inline="javascript">
		layui.use(['form','layer'], function() {
			var form = layui.form,
				layer = layui.layer,
				$ = layui.jquery;
				
			var id = getUrlParam("id");

			var accessBaseUrl =[[${entityData.accessBaseUrl}]];

			var entityName = [[${entityData.entityName}]];

			$.ajax({
            	url:accessBaseUrl+entityName+"/"+id,
            	type:'GET',
            	data:{},
            	cache: false,
            	async:true,
            	headers:{
		    		Authorization:Authorization
		    	},
            	success:function(res){
            		if(res.code == 200){
            			for(var item in res.data){
							$("input[name='"+item+"']").val(res.data[item]);
            			}
						form.render();
					}
            	}
            });
			
				
			//监听提交
			form.on('submit(save)', function(data) {
				var result = data.field;
				
				var load = layer.load(2);
				
				$.ajax({
	            	url:accessBaseUrl+entityName,
	            	type:'PUT',
	            	data:JSON.stringify(result),
	            	contentType: 'application/json',
	            	cache: false,
	            	async:true,
	            	headers:{
			    		Authorization:Authorization
			    	},
	            	success:function(res){
	            		if(res.code == 200){
							layer.msg(res.message,{icon:1,time: 500},function (){
								$('#cancerBtn').click();
								parent.layui.table.reload('dataTable');
							});
						}
						layer.close(load);
	            	}
	            });
	            
				return false;
			});
			
			$('#cancerBtn').on('click',function(){
				var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				parent.layer.close(index);
			});
			
		});
	</script>
</body>
</html>
